//package com.ruoyi.quartz.edh;
//
//import com.ruoyi.common.utils.SecurityUtils;
//import com.ruoyi.edh.domain.EdhOrder;
//import com.ruoyi.edh.mapper.EdhOrderMapper;
//import com.ruoyi.edh.service.IEdhOrderService;
//import lombok.extern.log4j.Log4j2;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.scheduling.annotation.EnableScheduling;
//import org.springframework.scheduling.annotation.Scheduled;
//import java.util.Calendar;
//import java.util.Date;
//import java.util.GregorianCalendar;
//import java.util.List;
//
//@Configuration
//@EnableScheduling
//@Log4j2
//public class OrderStatusQuartz {
//    @Autowired
//    private EdhOrderMapper edhOrderMapper;
//    @Autowired
//    private IEdhOrderService edhOrderService;
//    @Value("${cancelDateDay}")
//    private String cancelDataDay;
//    @Value("${shipDataDay}")
//    private String shipDataDay;
//
//   @Scheduled(cron = "0/60 * * * * ?")
//   private void orderStatusChange() {
//       log.info("定时任务订单自动修改开始");
//           List<EdhOrder> edhOrders = edhOrderMapper.queryAllOrderStatus();
//           Calendar calendar   =   new GregorianCalendar();
//       for (EdhOrder r : edhOrders) {
//           try {
//               String orderStatus = r.getOrderStatus();
//               EdhOrder edhOrder =new EdhOrder();
//               edhOrder.setId(r.getId());
//               switch (orderStatus) {
//                   case "0":
//                       //获取下单时间
//                       calendar.setTime(r.getCreateTime());
//                       calendar.add(Calendar.DATE, Integer.valueOf(cancelDataDay));
//                       Date time = calendar.getTime();
//                       //当前时间大于预计自动取消时间后设置状态
//                       if (System.currentTimeMillis()>time.getTime()){
//                           edhOrder.setCancelTime(new Date());
//                           edhOrder.setOrderStatus("4");
//                       }
//                       break;
//                   case "2":
//                       //获取待发货时间
//                       calendar.setTime(r.getShipTime());
//                       calendar.add(Calendar.DATE, Integer.valueOf(shipDataDay));
//                       Date date = calendar.getTime();
//                       //当前时间大于预计自动收货时间后设置状态
//                       if (System.currentTimeMillis()>date.getTime()){
//                           edhOrder.setCancelTime(new Date());
//                           edhOrder.setOrderStatus("3");
//                           edhOrder.setShipStatus("1");
//                           edhOrderService.insertProfitAndBill(r.getId());
//                       }
//                       break;
//                   default:
//                       break;
//               }
//               if (edhOrder.getOrderStatus()!=null) {
//                   edhOrderService.updateOrderStatus(edhOrder);
//                   //订单自动修改添加记录
//                   edhOrderMapper.addOrderLog(SecurityUtils.getUserId(), edhOrder.getId(), "系统自动状态修改");
//               }
//           } catch (Exception e) {
//               log.error("定时任务订单自动修改发生异常");
//           }
//       }
//       log.info("定时任务订单自动修改结束");
//   }
//
//
//}
